import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex); //vue的插件机制
import createPersistedState from "vuex-persistedstate";

//Vuex.Store 构造器选项
const store = new Vuex.Store({
	state: {
		"playState": false, //记录是不是在播放
		'pattern': {
			patternIndex: 0,
			list: [{
				icon: 'lbbf.png',
				name: '列表循环',
				index: 0
			}, {
				icon: 'dqbf.png',
				name: '单曲循环',
				index: 1
			}, {
				icon: 'lxbf.png',
				name: '随机播放',
				index: 2
			}]
		}, //播放模式
		"songSheet": {
			"playIndex": 0,
			"list": [
			],
		},

	},
	mutations: {
		setPlayIndex(state, value) {
			state.songSheet.playIndex = value
		},
		downPlayIndex(state) {
			if (state.songSheet.list.length != state.songSheet.playIndex + 1) {
				state.songSheet.playIndex++
			} else {
				state.songSheet.playIndex = 0
			}
		},
		upPlayIndex(state) {
			if (!state.songSheet.playIndex - 1 < 0) {
				state.songSheet.playIndex--
			} else {
				state.songSheet.playIndex = state.songSheet.list.length - 1
			}
		},
		setSongSheetList(state,value){
			state.songSheet.list=value
		},
		setPlayState(state, value) {
			state.playState = value
		},
		setPattern(state) {
			if (state.pattern.patternIndex + 1 != state.pattern.list.length) {
				state.pattern.patternIndex++
			} else {
				state.pattern.patternIndex = 0
			}
		}
	},
	plugins: [
		createPersistedState({
			storage: {
				getItem: key => uni.getStorageSync(key),
				setItem: (key, value) => uni.setStorageSync(key, value),
				removeItem: key => uni.removeStorageSync(key)
			}
		})
	],

})
export default store
